import fs from 'fs'
import { fileURLToPath } from 'url'
export const getC = function(){
    let Curl=new URL('../controllers',import.meta.url).href
    let Cpath=fileURLToPath(Curl);
    let fileArr=fs.readdirSync(Cpath).filter(item=>item.endsWith('Controllers.js'));
    let filePath =fileArr.map(item=>`${Curl}/${item}`)
    return filePath
}
export const regC=function(router,controllerFiles){
    controllerFiles.forEach(async item=>{
        let { default:arr }=await import(item)
        arr.forEach(obj=>{
            if (obj.method==='get'){
                router.get(obj.url,obj.fn)
            }
            if (obj.method==='post'){
                router.post(obj.url,obj.fn)
            }
            if (obj.method==='put'){
                router.put(obj.url,obj.fn)
            }
            if (obj.method==='del'){
                router.delete(obj.url,obj.fn)
            }
        })
    })

    }
